package pers.cz.logtail.handle.adapter;

import pers.cz.config.JefConfiguration;
import pers.cz.logtail.connect.redis.RedisConnection;
import pers.cz.logtail.db.redis.RedisPoolFactory;
import pers.cz.logtail.enums.RedisConfigItem;
import pers.cz.netty.protocal.Message;
import pers.cz.util.DateUtils;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import java.util.Date;
import java.util.Map;

/**
 * @program: JefLogTail
 * @description: 使用redis保存
 * @author: Cheng Zhi
 * @create: 2023-03-04 20:49
 **/
public class RedisAdapter extends AbstractLogSaveAdapter {

    private static final String DEFAULT_KEY = "JEF-LOG-TAIL";

    @Override
    public void save(Message message) {

        JedisPool jedisPool = RedisPoolFactory.getJedisPool();
        RedisConnection redisConnection = new RedisConnection(jedisPool);
        String defaultKey = message.getAttachment("ip") + "_" + message.getAttachment("fileName");
        String key = JefConfiguration.get(RedisConfigItem.REDIS_KEY_NAME, defaultKey);
        redisConnection.insert(key, (String) message.getContent());
    }
}
